﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class PlanarGeneralWcsActionBO : BytesObjectBase
    {
        public short ActionType { get; set; }
        public int TaskCode { get; set; }
        public int ToEquipmentCode { get; set; }
        public string PalletBarcode { get; set; }
        //public short IsFull { get; set; }
        public byte PalletType { get; set; }
        public byte AlrmCode { get; set; }
        /// <summary>
        /// 预留
        /// </summary>
        public byte Reserve { get; set; }
        public byte Reserve2 { get; set; }
        public byte Reserve3 { get; set; }
        public byte Reserve4 { get; set; }

        //public override byte[] Derialize()
        //{
        //    throw new NotImplementedException();
        //}

        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            ObjectType = objectType;


            EquipmentCode = HelperByte.GetDIntAt(bytes, 0).ToString();
            TaskCode = HelperByte.GetDIntAt(bytes, 4);
            ToEquipmentCode = HelperByte.GetDIntAt(bytes, 8);
            int length = HelperByte.GetSIntAt(bytes, 13);
            PalletBarcode = HelperByte.GetCharsAt(bytes, 14, length);
            ActionType = HelperByte.GetIntAt(bytes, 32);
            PalletType = HelperByte.GetByteAt(bytes, 34);
            AlrmCode = HelperByte.GetByteAt(bytes, 35);
            Reserve = HelperByte.GetByteAt(bytes, 36);//视觉检测则是显示电池数量
            Reserve2 = HelperByte.GetByteAt(bytes, 37);
            Reserve3 = HelperByte.GetByteAt(bytes, 38);
            Reserve4 = HelperByte.GetByteAt(bytes, 39);


            //length = HelperByte.GetSIntAt(bytes, 1);
            //EquipmentCode = HelperByte.GetDIntAt(bytes, 0);
            //TaskCode = HelperByte.GetDIntAt(bytes, 8);
            //length = HelperByte.GetSIntAt(bytes, 13);
            //ToEquipmentCode = HelperByte.GetCharsAt(bytes, 14, length);
            //length = HelperByte.GetSIntAt(bytes, 21);
            //PalletBarcode = HelperByte.GetCharsAt(bytes, 22, length);
            //IsFull = HelperByte.GetIntAt(bytes, 40);
            //ActionType = HelperByte.GetIntAt(bytes, 42);
            //Reserve = HelperByte.GetIntAt(bytes, 44);
            //Reserve2 = HelperByte.GetIntAt(bytes, 46);
        }
    }
}
